
'use strict';

const Controller = require('egg').Controller;

class BaseController extends Controller {

    async userId() {
        const { ctx, app } = this;
        const token = ctx.request.header.token;
        const userId = await app.redis.get(token);
        return userId;
        // return 1;
    }

    async onlineSwitch(object) {
        if (object.online) {
            object.online = false;
        } else {
            object.online = true;
        }
        object.save();
    }

    async olineSwitch(object) {
        if (object.oline) {
            object.oline = false;
        } else {
            object.oline = true;
        }
        object.save();
    }

    async recommendSwitch(object) {
        if (object.recommend) {
            object.recommend = false;
        } else {
            object.recommend = true;
        }
        object.save();
    }

    async hotSwitch(object) {
        if (object.hot) {
            object.hot = false;
        } else {
            object.hot = true;
        }
        object.save();
    }


}

module.exports = BaseController;